import { useRoute, useRouter } from 'vue-router';
import { useUserContext } from '@/store/modules/user-context';

/**
 * 路由工具函数
 */

// 获取当前路由的 uniqueStr 参数
export function getUniqueStr(): string {
  const userContext = useUserContext();
  return userContext.getUniqueStr;
}

// 从路由参数中获取 uniqueStr（用于初始化）
export function getUniqueStrFromRoute(): string {
  const route = useRoute();
  return route.params.uniqueStr as string;
}

// 生成带 ucenter 前缀的路径
export function getUcenterPath(uniqueStr: string, path: string): string {
  return `/ucenter/${uniqueStr}${path}`;
}

// 获取当前用户的完整路径
export function getCurrentUserPath(path: string): string {
  const uniqueStr = getUniqueStr();
  return getUcenterPath(uniqueStr, path);
}

// 导航到当前用户的指定路径
export function navigateToUserPath(path: string) {
  const router = useRouter();
  const uniqueStr = getUniqueStr();
  const fullPath = getUcenterPath(uniqueStr, path);
  router.push(fullPath);
}

// 替换到当前用户的指定路径
export function replaceToUserPath(path: string) {
  const router = useRouter();
  const uniqueStr = getUniqueStr();
  const fullPath = getUcenterPath(uniqueStr, path);
  router.replace(fullPath);
}